package com.CGFrame.struts.bean.project;

import java.util.Iterator;

import com.CGFrame.struts.POJOs.Element;
import com.CGFrame.struts.POJOs.Elementgroup;
import com.CGFrame.struts.POJOs.Project;
import com.CGFrame.struts.POJOs.Status;
import com.CGFrame.struts.bean.ProjectOperate;
import com.CGFrame.struts.bean.ProjectOperateFactory;

public class ElementFileLogic {
	public static void addElements(ElementFileBean eFBean,String projectId) throws Exception
	{
		ProPathConst ppc = new ProPathConst();
		
		ProjectOperate pop = ProjectOperateFactory.getprojectOperate();
		Project project = (Project)pop.UniqueQuery("Project", "projectId,"+projectId);
		Iterator ite_ElementGroups = project.getElementgroups().iterator();
		ProjectAddFile pAF = new ProjectAddFile();
		Status status = (Status)pop.UniqueQuery("Status", "statusName,HasInput,statusType,Element");
		while(ite_ElementGroups.hasNext())
		{
			Elementgroup eg = (Elementgroup)ite_ElementGroups.next();
			if(  eg.getElementGroupName().equals(ppc.getParam7()) ) //characters
			{
				String[] ary_Characters = eFBean.getCharacters();
				if (ary_Characters==null) continue;
				String[] ary_CharactersShort = eFBean.getCharactersShort();
				pAF.addElement(ary_Characters, eg);
				int length = ary_Characters.length;
				for (int i = 0 ; i<length ; i++)
				{
					if (ary_Characters[i]!=null && ary_Characters[i].equals("")==false)
					{
						Element ele = new Element();
						ele.setElementName(ary_Characters[i]);
						ele.setShortening(ary_CharactersShort[i]);
						ele.setElementgroup(eg);
						ele.setStatus(status);
						pop.saveObject(ele);
						
					}
				}
				
			}
			else if(  eg.getElementGroupName().equals(ppc.getParam8()) ) //props
			{
				String[] ary_Props = eFBean.getProps();
				if (ary_Props==null) continue;
				
				String[] ary_PropsShort = eFBean.getPropsShort();
				pAF.addElement(ary_Props, eg);
				int length = ary_Props.length;
				for (int i = 0 ; i<length ; i++)
				{
					if (ary_Props[i]!=null && ary_Props[i].equals("")==false)
					{
						Element ele = new Element();
						ele.setElementName(ary_Props[i]);
						ele.setShortening(ary_PropsShort[i]);
						ele.setElementgroup(eg);
						ele.setStatus(status);
						pop.saveObject(ele);
						
					}
				}
			}
			else if(  eg.getElementGroupName().equals(ppc.getParam9()) ) //sceneset
			{
				String[] ary_Scenes = eFBean.getScenes();
				if (ary_Scenes==null) continue;
				
				String[] ary_ScenesShort = eFBean.getScenesShort();
				pAF.addElement(ary_Scenes, eg);
				int length = ary_Scenes.length;
				for (int i = 0 ; i<length ; i++)
				{
					if (ary_Scenes[i]!=null && ary_Scenes[i].equals("")==false)
					{
						Element ele = new Element();
						ele.setElementName(ary_Scenes[i]);
						ele.setShortening(ary_ScenesShort[i]);
						ele.setElementgroup(eg);
						ele.setStatus(status);
						pop.saveObject(ele);
						
					}
				}
			}
			
		}
	}

}
